package com.nageffer.shortlink.project.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 布隆过滤器配置
 */
@Configuration
public class RBloomFilterConfiguration {

    /**
     * 防止短链接创建查询数据库的布隆过滤器
     */
    @Bean
    public RBloomFilter<String> shortlinkCreatePenetrationBloomFilter(RedissonClient redissonClient) {
        //设置布隆过滤器的名字
        RBloomFilter<String> cachePenetrationBloomFilter = redissonClient.getBloomFilter("shortlinkCreatePenetrationBloomFilter");
        //设置预估布隆过滤器存储的元素容量、运行的误判率
        cachePenetrationBloomFilter.tryInit(100000000, 0.001);//大约占171M内存
        return cachePenetrationBloomFilter;
    }

}
